// AdresseImpl.cpp: implementation of the CAdresseImpl class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "AdresseImpl.h"
#include "importado.h"
#include "Database.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAdresseImpl::CAdresseImpl()
{
	m_adresseType = bstr_t("");
	m_email = bstr_t("");
	m_gade = bstr_t("");
	m_telefax = bstr_t("");
	m_telefon = bstr_t("");
	m_postNr = bstr_t("");
	m_guid = bstr_t("");
	m_attention = bstr_t("");
}

CAdresseImpl::~CAdresseImpl()
{

}

bstr_t CAdresseImpl::get_AdresseType()
{
	return m_adresseType.copy();
}

bstr_t CAdresseImpl::get_Email()
{
	return m_email.copy();
}

bstr_t CAdresseImpl::get_Gade()
{
	return m_gade.copy();
}

bstr_t CAdresseImpl::get_Telefax()
{
	return m_telefax.copy();
}

bstr_t CAdresseImpl::get_Telefon()
{
	return m_telefax.copy();
}

bstr_t CAdresseImpl::get_PostNr()
{
	return m_postNr.copy();
}

bstr_t CAdresseImpl::get_By()
{
	return m_by.copy();
}

void CAdresseImpl::put_AdresseType(bstr_t val)
{
	m_adresseType = val;
}

void CAdresseImpl::put_Email(bstr_t val)
{
	m_email = val;
}

void CAdresseImpl::put_Gade(bstr_t val)
{
	m_gade = val;
}

void CAdresseImpl::put_Telefax(bstr_t val)
{
	m_telefax = val;
}

void CAdresseImpl::put_Telefon(bstr_t val)
{
	m_telefon = val;
}

void CAdresseImpl::put_PostNr(bstr_t val)
{
	m_postNr = val;
}

void CAdresseImpl::put_By(bstr_t val)
{
	m_by = val;
}

bool CAdresseImpl::SetInfo(bstr_t studentGuid)
{
	_CommandPtr cmd;
	_RecordsetPtr recordset;

	const char sql[255] = "EBAS_SP_GEM_ADRESSE";

	try {			
		cmd.CreateInstance(__uuidof(Command));
		cmd->ActiveConnection = CDatabase::GetConnection();
		cmd->CommandText = sql;
		cmd->CommandType = adCmdStoredProc;

		cmd->Parameters->Append( cmd->CreateParameter("session", adVarChar, adParamInput, 255, gpSessionGuid) );
		cmd->Parameters->Append( cmd->CreateParameter("studGuid", adVarChar, adParamInput, 50, studentGuid) );		
		cmd->Parameters->Append( cmd->CreateParameter("attention", adVarChar, adParamInput, 255, m_attention) );				
		cmd->Parameters->Append( cmd->CreateParameter("email", adVarChar, adParamInput, 255, m_email) );
		cmd->Parameters->Append( cmd->CreateParameter("gade", adVarChar, adParamInput, 255, m_gade) );
		cmd->Parameters->Append( cmd->CreateParameter("postnr", adVarChar, adParamInput, 255, m_postNr) );
		cmd->Parameters->Append( cmd->CreateParameter("telefax", adVarChar, adParamInput, 255, m_telefax) );
		cmd->Parameters->Append( cmd->CreateParameter("telefon", adVarChar, adParamInput, 255, m_telefon) );
		cmd->Parameters->Append( cmd->CreateParameter("adresseType", adVarChar, adParamInput, 255, m_adresseType) );
		cmd->Execute(NULL, NULL, adCmdStoredProc);				
	} catch (_com_error &e) {
		CErrorHandling::SetErrorMessage(e.ErrorMessage());
		return FALSE;
		char err[512];
		strncpy(err, e.ErrorMessage(), 512);
		return FALSE;
	}

	return TRUE;
}

void CAdresseImpl::put_GUID(bstr_t val)
{
	m_guid = val;
}

bstr_t CAdresseImpl::get_GUID()
{
	return m_guid.copy();
}

bstr_t CAdresseImpl::get_Attention()
{
	return m_attention.copy();
}

void CAdresseImpl::put_Attention(bstr_t val)
{
	m_attention = val;
}